﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Admin.Application.Contracts.DTOs.MqttDtos.Sensors;
using PHMEE.Admin.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace PHMEE.Admin.HttpApi.Controllers.MqttInfo
{
    /// <summary>
    /// 采集器配置
    /// </summary>
    [Route("phmeeadmin/api/[controller]/[action]")]
    public class SysParaController : PHMEEAdminController
    {
        private readonly ISysParaAppService _sysParaAppService;
        private readonly ISensorAppService sensorAppService;


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sysParaAppService"></param>
        public SysParaController(ISysParaAppService sysParaAppService, ISensorAppService sensorAppService)
        {
            _sysParaAppService = sysParaAppService;
            this.sensorAppService = sensorAppService;
        }
        /// <summary>
        /// 根据id查询采集站
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysParaByIdDto> GetSysParaById(Guid id)
        {
            return await _sysParaAppService.GetByIdAsync(id);
        }

        /// <summary>
        /// 根据采集站编码查询--下发参数使用
        /// </summary>
        /// <param name="collectorCode">采集站编码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysParaDto> GetByIdUseMqtt(string collectorCode)
        {
            return await _sysParaAppService.GetByIdUseMqttAsync(collectorCode);
        }
        /// <summary>
        /// 查看数采器配置信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysParaListResultDto> GetPageSysPage(PageSysParaDto input)
        {
            return await _sysParaAppService.GetAllSysParaAsync(input);
        }
        /// <summary>
        /// 新增采集器配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<SysParaListDto> CreateSysPara(SysParaCreateDto input)
        {
            return await _sysParaAppService.CreateSysParaAsync(input);
        }
        /// <summary>
        /// 编辑采集站信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateSysPara(SysParaUpdateDto input)
        {
            await _sysParaAppService.UpdateAsync(input);
            return Ok(new { Message = "Success" });
        }
        /// <summary>
        /// 根据数采器编号查看扩展信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SysParaExtendDto> GetSysParaEntend(string code)
        {
            return await _sysParaAppService.GetSyaParaExtendAsync(code);
        }
        /// <summary>
        /// 删除采集站信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteSysPara(Guid id)
        {
            await _sysParaAppService.DeleteAsync(id);
            return Ok(new { Message = "Success" });
        }
        /// <summary>
        /// 获取传感器数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SensorResultDto>> GetSensorsWithSensor(PageSensorDto input)
        {
            return await sensorAppService.GetSensorsWithSensorAsync(input);
        }
    }
}
